var formidable = require('formidable');
var fs = require('fs');
var http = require('http');

http.createServer(function (req, resp) {
    console.log(req.url);
    if (req.url == '/upload') {
        upload(req, resp)
    } else {
        var data = fs.readFileSync(__dirname + '/upload.html', 'utf-8');
        resp.end(data);
    }
}).listen(3000);

function upload(req, resp) {
    var form = new formidable.IncomingForm();
    form.parse(req, function (error, fields, files) {
        console.log(files);
        fs.renameSync(files.file.path, __dirname + '/test.js');
        resp.end('success');
    });
}

var uri = encodeURI('我.jpg');
console.log(uri);
